package fr.nts.framework.front.form.validation;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;

import com.google.common.collect.Maps;

/**
 * Représente le résultat d'une validation NTS sur un champ d'un formulaire
 * 
 * @author sco
 * @version 1.0.0
 */
public class FieldValidationResult implements Serializable{

	private static final long serialVersionUID = 1L;

	/**
	 * Le résultat de validation
	 */
	private boolean valid = false;
	
	/**
	 * Résultat ok
	 */
	public static FieldValidationResult ok = new FieldValidationResult(true);
	
	/**
	 * Le code d'erreur de la validation
	 */
	private Map<String,List<String>> errorCodes = Maps.newHashMap();

	
	public FieldValidationResult(boolean valid){
		this.valid = valid;
	}

	public FieldValidationResult(Map<String,List<String>> errorCodes){
		this.valid = false;
		this.errorCodes = errorCodes;
	}
	
	
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString(){
		return new ToStringBuilder(this).append("valid", valid)
		                                .append("Nb errorCode", errorCodes.size())
		                                .toString();
	}
	
	
	// GETTER / SETTER
	public boolean isValid(){
		return valid;
	}

	public void setValid(boolean valid){
		this.valid = valid;
	}

	public Map<String, List<String>> getErrorCodes(){
		return errorCodes;
	}

	public void setErrorCodes(Map<String, List<String>> errorCodes){
		this.errorCodes = errorCodes;
	}
}